<?php
/*
Plugin Name: QRcode for TC
QRcode URI: http://qrcode.kaywa.com/
Description: Add the QRcode to your Entry title
Version: 0.1
Author: Cain Chen, Hinablue.
Author URI: http://hina.ushiisland.net/blog/
*/ 

function ShowQRcodeJavascript($target) {
	global $suri;
	
	if($suri['directive']!="/rss" && $suri['directive']!="/m" && $suri['directive']!="/i/entry" && $suri['directive']!="/atom" && $suri['directive']!="/sync") {
		ob_start();
		?>
		<script type="text/javascript">
		//<![CDATA[
		function showQR(Id, size, uri) {
			var _URI = 'http://qrcode.kaywa.com/img.php?s='+parseInt(size)+'&d='+uri;
			var _Html = '<img align="right" src="http://qrcode.kaywa.com/tmpl/default/web/media/logo.png" border="0" alt="qrcode" /><img src="'+_URI+'" alt="qrcode"><p align="right"><font size="-1">Powered By <a href="http://qrcode.kaywa.com/" target="_blank" rel="qrocde">http://qrcode.kaywa.com/</a><br />[Click anywhere to close]</font></p>';
			var showQR = document.getElementById('qrcode_'+parseInt(Id));
			showQR.innerHTML = _Html;
			showQR.style.display = 'block';
		};
		//]]>
		</script>
		<?
		$target .= ob_get_contents();
		ob_end_clean();
	}
	return $target;
}

function ShowQRcode($target, $mother) {
	global $configVal, $owner, $suri, $defaultURL, $pluginURL, $blog, $entries;
	requireComponent('Textcube.Function.misc');
	$data = misc::fetchConfigVal($configVal);
	$__size = (!is_null($data) && array_key_exists('QRcodeShowUpSize', $data)) ? $data['QRcodeShowUpSize'] : 8 ;

	$permalink	= "{$defaultURL}/m/".$mother;

	if($suri['directive']!="/rss" && $suri['directive']!="/m" && $suri['directive']!="/i/entry" && $suri['directive']!="/atom" && $suri['directive']!="/sync")
	{
		$QRcode = '<div class="qrcode"><img src="'.$pluginURL.'/qrcodeicon.png" border="0" width="16" height="16" alt="qrcode" onclick="showQR('.$mother.','.$__size.',\''.urlencode($permalink).'\');" style="cursor: pointer;" />&nbsp;<font size="-1">Mobile:<a href="'.$permalink.'" rel="tag">'.$permalink.'</a></font></div><div align="center" id="qrcode_'.$mother.'" style="width:90%;padding:20px;cursor:pointer;display:none;" onClick="this.innerHTML=\'\'; this.style.display=\'none\';"></div>';
	}
	return $QRcode . $target;
}

function QRcode_DataSet($data)
{
	requireComponent('Textcube.Function.misc');
	$data = misc::fetchConfigVal($configVal);
	if(is_null($data)){
		$data['QRcodeShowUpSize']	= 6;
	}
	$cfg = misc::fetchConfigVal($data);
	return true;
}
?>